package com.health.viewscontrols.medical.adapter;

import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.health.R;
import com.health.tablebean.CD_DRUGCONDITION;
import com.health.viewscontrols.medical.base.DeviceEnum;

import java.util.List;

public class SfDrugAdapter extends BaseQuickAdapter<CD_DRUGCONDITION, BaseViewHolder> {


    public SfDrugAdapter(int layoutResId, @Nullable List<CD_DRUGCONDITION> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CD_DRUGCONDITION item) {
        helper.setIsRecyclable(false);
        helper.setText(R.id.et_ywmc, notNull(item.getNAME()));
        helper.setText(R.id.nice_spinner_dw1, notNull(item.getRES1()));
        helper.setText(R.id.drugTime1, notNull(item.getRES2()));

        helper.setText(R.id.ed_ywmc1_mg, notNull(String.valueOf(item.getEVERYTIMEMG())));
        helper.setText(R.id.nice_spinner_yl1, notNull(item.getRES3()));
        helper.setText(R.id.nice_spinner_cc1, notNull(item.getRES4()));
//        String dailytime = item.getDAILYTIME();
//        if(null != dailytime && !dailytime.equals("")){
//            if(dailytime.contains("/")){
//                String[] split = dailytime.split("/");
//                if(null != split && !split.equals("")){
//                    String s = split[1];
//                    if(null != s && !s.equals("")){
//                        helper.setText(R.id.nice_spinner_yl1, notNull(s));
//                    }
//                    String s1 = split[0];
//                    if(null != s1 && !s1.equals("")){
//                        helper.setText(R.id.nice_spinner_cc1, notNull(s1));
//                    }
//                }
//            }
//        }

        helper.addOnClickListener(R.id.tvdrug);

        AutoCompleteTextView ywmc = helper.getView(R.id.et_ywmc);
        ywmc.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setNAME(s.toString());
            }
        });

        AutoCompleteTextView nice_spinner_cc1 = helper.getView(R.id.nice_spinner_cc1);
        nice_spinner_cc1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setRES4(s.toString());
            }
        });

        AutoCompleteTextView nice_spinner_yl1 = helper.getView(R.id.nice_spinner_yl1);
        nice_spinner_yl1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setRES3(s.toString());
            }
        });

        AutoCompleteTextView ed_ywmc1_mg = helper.getView(R.id.ed_ywmc1_mg);
        ed_ywmc1_mg.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setEVERYTIMEMG(s.toString());
            }
        });

        AutoCompleteTextView nice_spinner_dw1 = helper.getView(R.id.nice_spinner_dw1);
        nice_spinner_dw1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setRES1(s.toString());
            }
        });

        EditText drugTime1 = helper.getView(R.id.drugTime1);
        drugTime1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setRES2(s.toString());
            }
        });
    }

    public static String notNull(String str) {
        if (TextUtils.isEmpty(str) || "null".equals(str) || "NULL".equals(str)) {
            return "";
        }
        return str;
    }

}
